<?php
$storage = Zend_Auth::getInstance()->getStorage();
$xml = 'public/xml/menu_'.$storage->read()->USU_ID.'.xml';
if(is_file($xml))
{
    $reader = new Zend_Config_Xml($xml);
    $menus = $reader->toArray();
//echo '<pre>';print_r($menus);echo '</pre>';
?>

<ul class="menu">
    <li>
        <a class="m_i_home" href="<?php echo $this->baseUrl($this->modulo.'/'); ?>">&nbsp; Início &nbsp;</a>
    </li>
<?php
foreach ($menus as $menu) {
    foreach ($menu as $men) {
        // corrigir erro quando tem apenas um menu.
        if(isset($men['nome'])) $men = array('0' => $men);        
        foreach ($men as $m) {                
?>
    
    <li><a href="javascript:void(0)" class="<?php echo $m['css']; ?>" ><?php echo $m['nome']; ?></a>
        <ul>
            <?php
            foreach ($m['modulos'] as $mod) {
                if (isset($mod[0])) {
                    foreach ($mod as $item) { ?>  
                    <li><a href="<?php echo $this->baseUrl($this->modulo.'/'.$item['arquivo']); ?>"><?php echo $item['nome']; ?></a></li>
                        <?php
                    }
                } else if (isset($mod['id'])) { ?>  
                    <li><a href="<?php echo $this->baseUrl($this->modulo.'/'.$mod['arquivo']); ?>"><?php echo $mod['nome']; ?></a></li>
                <?php
            }
        }
        ?>
        </ul>
    </li>
    
<?php       
        }
    }
}
?>
    <li>
        <a class="m_i_exit" onclick="if(confirm('Deseja sair do sistema?')) location = '<?php echo $this->baseUrl($this->modulo.'/auth/logout')?>';" href="javascript:void(0)"> &nbsp; Sair &nbsp; </a>
    </li>
</ul>


<?php
}
else echo '<br>Arquivo de menu inexistente!<br>';

?>


